<?php

namespace app\mall\controller;

use app\admin\controller\api\Upload;
use app\mall\logic\indexLogic;
use app\mall\logic\orderLogic;
use app\mall\logic\uploadLogic;
use think\admin\Controller;
use think\facade\Log;

class Index extends Controller
{

    /**
     * 商品分类
     * @return void
     */
    public function goods_classify()
    {
        $pid = request()->param('pid', 0);
        $logic = new indexLogic();
        $data = $logic->goods_classify($pid);
        $this->success('商品分类', $data);
    }

    /**
     * 商品列表
     * @return void
     */
    public function goods_list()
    {
        $is_new = request()->param('is_new', 0);
        $is_hot = request()->param('is_hot', 0);
        $order = request()->param('order', 'create_time');
        $sort = request()->param('sort', 'desc');
        //  安全过滤
        $sort = strtoupper($sort)  !== 'DESC' ? 'ASC' : 'DESC';

        $one_cate_id = request()->param('one_cate_id', 0);
        $two_cate_id = request()->param('two_cate_id', 0);
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);
        $logic = new indexLogic();
        $data = $logic->goods_list($one_cate_id, $two_cate_id, $is_hot, $is_new, $order, $sort, $page, $limit);
        $this->success('商品列表', $data);
    }

    public function drawing_list() {
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);

        $logic = new indexLogic();
        $items = $logic->drawing_list($page, $limit);
        $this->success('最新揭晓', $items);
    }

    public function thugs_list() {
        $page = request()->param('page', 1);
        $limit = request()->param('limit', 10);

        $logic = new indexLogic();
        $items = $logic->thugs_list($page, $limit);
        $this->success('零錢富豪榜', $items);
    }

    public function quick_buys()
    {
        $keys = 'quick-cart';
        $items = sysdata($keys);

        $this->success('一键加购', $items);
    }

    /**
     * 商品详情
     * @return void
     */
    public function goods_details()
    {
        $id = request()->param('id', 0);
        $uid = request()->param('uid', 0);
        $logic = new indexLogic();
        $data = $logic->goods_details($id, $uid);
        $this->success('商品详情', $data);
    }

    /**
     * 购买榜单
     * @return void
     */
    public function lottery_board()
    {
        $id = request()->param('id', 0);
        $logic = new indexLogic();
        $data = $logic->lottery_board($id);
        $this->success('购买榜单', $data);
    }

    public function lottery_chart()
    {
        $id = request()->param('id', 0);
        $logic = new indexLogic();
        $data = $logic->lottery_chart($id);
        $this->success('开奖走势', $data);
    }

    /**
     * 轮播图
     * @return void
     * @throws \think\admin\Exception
     */
    public function rotation_chart()
    {
        $data = sysdata('carousel');
        $this->success('轮播图', $data);
    }

    /**
     * 推荐活动
     * @return void
     */
    public function promo_lucky_draw()
    {
        $logic = new indexLogic();
        $data = $logic->promo_goods();

        $this->success('推荐活动', $data);
    }

    /**
     * 支付宝订单回调
     * @return void
     */
    public function ali_notify()
    {
        Log::info('进入支付宝支付回调');
        $logic = new orderLogic();
        $data = $logic->ali_notify();

        echo $data;
    }

    /**
     * 支付宝充值回调
     * @return void
     */
    public function ali_recharge_notify()
    {
        Log::info('进入支付宝充值回调');
        $logic = new orderLogic();
        $data = $logic->ali_recharge_notify();

        echo $data;
    }

    //超时订单取消
    public function auto_cancle()
    {

        $logic = new orderLogic();
        $res = $logic->auto_cancle();

        $this->success('超时订单取消', []);
    }
}